package com.zhn.evsi.controller.Market;

import cn.hutool.core.util.ObjectUtil;
import com.zhn.evsi.common.Result;
import com.zhn.evsi.domain.dto.Market.MarketOrderDTO;
import com.zhn.evsi.domain.dto.Market.MarketOrderSearchDTO;
import com.zhn.evsi.domain.entity.Market.MarketOrder;
import com.zhn.evsi.service.IMarketOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品货架
 *
 * */
@Api(tags = "商城货架")
@RestController
@RequestMapping("/market/order")
public class MarketOrderController {

    @Autowired
    private IMarketOrderService marketOrderService;

    /**
     * 商品列表
     * */
    @ApiOperation("商品列表")
    @GetMapping("/list")
    public Result orderList(@RequestParam MarketOrderDTO marketOrderDTO) {
        List<MarketOrder> marketOrderList = marketOrderService.orderList(marketOrderDTO);
        return Result.success(marketOrderList);
    }

    /**
     * 商品新增
     * */
    @ApiOperation("商品新增")
    @PostMapping("/add")
    public Result addOrders(@RequestBody MarketOrderDTO marketOrderDTO) {
        marketOrderService.addOrders(marketOrderDTO);
        return Result.success();
    }

    /**
     * 新增输入商品名称自动填充
     *
     * @param search - 模糊查询自动填充字段
     * */
    @ApiOperation("模糊查询自动填充")
    @GetMapping("/search")
    public Result search(@RequestParam String search) {
        if (ObjectUtil.equal("", search)){
            return Result.success();
        }
        List<MarketOrderSearchDTO> orderSearchDTOList = marketOrderService.search(search);
        return Result.success(orderSearchDTOList);
    }

    /**
     * 合同市场，通过读取合同信息，将数据放入到sql中，并显示时间、地点、金额、图片、名称、
     * */
}
